package com.epam.iunna.bookshop.controller.utils;

import javax.servlet.http.HttpSession;

import com.epam.iunna.bookshop.controller.filters.AuthFilter;
import com.epam.iunna.bookshop.model.User;

/**
 * 
 * @author
 * 
 */
public final class UserSessionHelper {
    
    /**
     * Конструктор Класса.
     */
    public UserSessionHelper() {
    }

    /**
     * Get role for current logged in user 
     * 
     * @return user role or null if no user was logged in or if no roles were attached to him.
     */
    public String getUserRole(HttpSession session) {
    	if( session.getAttribute( AuthFilter.USER_SESSION_KEY ) instanceof User){
    	    return ((User)session.getAttribute( AuthFilter.USER_SESSION_KEY )).getRole();
    	}
        return null;
    }
}
